package com.beadhouse.nurrecord.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.beadhouse.common.dto.JSONResponse;
import com.beadhouse.common.dto.QueryResult;
import com.beadhouse.common.exeption.BeadHouseException;
import com.beadhouse.entity.CustomerAndNurcontentEntity;
import com.beadhouse.nurrecord.ao.NursingProjectAo;
import com.beadhouse.nurrecord.service.NursingRecordsService;
import com.beadhouse.nurrecord.support.service.NursingRecordsServiceImpl;

/**
 * 
 * @author 刘聪
 *
 */
@Controller
@RequestMapping("/api/nurrecord")
public class NursingRecordsServlet {

	@Autowired
	NursingRecordsService nrsi;

	@ResponseBody
	@RequestMapping("/recordList")
	public JSONResponse SelectRecordList(NursingProjectAo ao) {
		try {
			if (ao.getPageNo() == null) {
				ao.setPageNo("1");
			}
			if (ao.getPageSize() == null) {
				ao.setPageSize("5");
			}
			QueryResult<CustomerAndNurcontentEntity> list;
			list = nrsi.selectRecord(ao);
			return JSONResponse.ok(list);
		}catch (BeadHouseException e) {
			return JSONResponse.fail(e);
		} catch (Exception e) {
			return JSONResponse.fail(e);
		}
	}

	@ResponseBody
	@GetMapping("/recordDelete")
	public JSONResponse deleteRecord(String customerId, String nurContentId) {
		try {
			nrsi.deleteRecord(customerId, nurContentId);
			return JSONResponse.ok();
		} catch (BeadHouseException e) {
			return JSONResponse.fail(e);
		} catch (Exception e) {
			return JSONResponse.fail(e);
		}
	}
}
